//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System.Collections.Generic;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.Configuration;
using EntLibContrib.Resource.Configuration;
#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif


namespace EntLibContrib.Resource.Configuration.Tests
{
	[TestClass]
	public class InternalResourceConfigurationSourceFixture
	{
		private const string managerName = "InternalResourceManager";
		private const string providerName = "InternalResourceProvider";
		private const string resourceSectionName = "resourceConfiguration";
		private const string instrumentationSectionName = "instrumentationConfiguration";

		[TestMethod]
		public void CanDeserializeSerializedConfiguration()
		{
			IConfigurationSource configurationSource = new InternalResourceConfigurationSource();
			ResourceManagerSettings resourceManagerSettings = (ResourceManagerSettings)configurationSource.GetSection(ResourceManagerSettings.SectionName);
			InstrumentationConfigurationSection instrumentationConfigurationSection = (InstrumentationConfigurationSection)configurationSource.GetSection(InstrumentationConfigurationSection.SectionName);

			Assert.IsNotNull(resourceManagerSettings);
			Assert.AreEqual(resourceSectionName, ResourceManagerSettings.SectionName);
			Assert.AreEqual(1, resourceManagerSettings.ResourceManagers.Count);
			Assert.AreEqual(1, resourceManagerSettings.ResourceProviders.Count);
			Assert.AreEqual(managerName, resourceManagerSettings.DefaultResourceManager);

			Assert.IsNotNull(resourceManagerSettings.ResourceManagers.Get(managerName));
			Assert.AreEqual(managerName, resourceManagerSettings.ResourceManagers.Get(managerName).Name);
			Assert.AreEqual(providerName, resourceManagerSettings.ResourceManagers.Get(managerName).ResourceProvider);

			Assert.IsNotNull(instrumentationConfigurationSection);
			Assert.AreEqual(instrumentationSectionName, InstrumentationConfigurationSection.SectionName);
			Assert.IsFalse(instrumentationConfigurationSection.EventLoggingEnabled);
			Assert.IsFalse(instrumentationConfigurationSection.PerformanceCountersEnabled);
			Assert.IsFalse(instrumentationConfigurationSection.WmiEnabled);
		}
	}
}